<%-- 
    Document   : ContestInfo
    Created on : 3/04/2011, 06:57:58 PM
    Author     : Jhon
--%>

<%@page import="vo.VOProblem"%>
<%@page import="vo.VOScoreboard"%>
<%@page import="vo.VOSubmission"%>
<%@page import="util.EnumSearchParameter"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Date"%>
<%@page import="vo.VOContest"%>
<%@page import="control.Controller"%>
<%@page import="vo.VOUser"%>
<%@page import="vo.VOUser"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="HTML.*"%>
<%@include file="CheckSession.jsp"%>
<% HtmlBody b = new HtmlBody("Contest","");

   VOUser a = (VOUser) session.getAttribute("USER");
   if(a.isIsAdmin()){
   b.addUsuario(a.getHandle(), "Administrator");
   }else{
   b.addUsuario(a.getHandle(), "User");
   }
   HtmlSideBar s = new HtmlSideBar(true);
   Controller con = Controller.getInstance();
   VOContest p = (VOContest) session.getAttribute("CONTEST");
   HtmlContent c = new HtmlContent(p.getName());
   Date d = new Date();
   if(p.getStart().before(d)){
   c.addStory("<center>Contest Name: "+p.getName()+"<br>Start :"+p.getStart().toString()+"<br>End :"+p.getEnd().toString()+"</center>","");
   
   if(!con.isUserRegistered(a.getHandle(), p.getContestCode()))
   c.subcripcion();

   String[] datos2 ={"Code ","Name","Difficulty"};
   c.addInitLista("Problems","600", datos2);
    ArrayList<VOProblem> pro= con.listProblems(EnumSearchParameter.CONTEST, p.getContestCode());
   if(pro!=null && !pro.isEmpty())
   for(VOProblem sub: pro){
    datos2[0]=sub.getProblemCode();
    datos2[1]=String.valueOf(sub.getName());
    datos2[2]=String.valueOf(sub.getDifficulty());
    c.addDataLista(datos2);
   }
   c.addEndLista();

   String[] datos1 ={"Handle","Solved","Time"};
   c.addInitLista("ScoreBoard","600", datos1);
    ArrayList<VOScoreboard> score= con.getScoreBoard(p.getContestCode());
   if(score!=null && !score.isEmpty())
   for(VOScoreboard sub:score){
    datos1[0]=sub.getHandle();
    datos1[1]=String.valueOf(sub.getSolved());
    datos1[2]=String.valueOf(sub.getTime());
    c.addDataLista(datos1);
   }
   c.addEndLista();


   String[] datos ={"Date","Language","Veredic","Handle","Problem","Contest"};
   c.addInitLista("Submitions","600", datos);
   ArrayList<VOSubmission> list = con.listSubmissions(EnumSearchParameter.CONTEST, p);
   if(list!=null && !list.isEmpty())
   for(VOSubmission sub:list){
    datos[0]=sub.getDate().toString();
    datos[1]=sub.getLanguage();
    datos[2]=sub.getVerdict();
    datos[3]=sub.getUserHandle();
    datos[4]=sub.getProblemCode();
    datos[5]=sub.getContestCode();
    c.addDataLista(datos);
   }
   c.addEndLista();





   }else{
   c.addFeature("Contest not active.", "the contest "+p.getName()+" will begin until "+p.getStart().toString()+" and today is "+d.toString(), "advertencia.gif", "100", "100");
   }
   b.addContent(c.getContent());
   b.addSideBar(s.getBar());
    %>

    <%=b.getHtml()%>